home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / Expander / Expander Classes / CExpanderText.cp < prev    next >
Encoding:
Text File  |  1994-11-30  |  3.3 KB  |  171 lines  |  [TEXT/KAHL]

  1. /***********************************************************************************
  2.     CExpanderText.cp
  3.  
  4.     Copyright © 1994 B-Ray Software. All rights reserved.
  5.     Developed using Symantec C++ 7.0.2 and Symantec's TCL library.
  6.     Portions of this code courtesy Symantec, Inc.
  7.  
  8.     This code may be freely distributed as long as this notice remains. This code
  9.     may not be used in any commercial software without the consent of B-Ray Software.
  10.  
  11.     ---
  12.  
  13. ***********************************************************************************/
  14. #include "ExpanderMessages.h"
  15.  
  16. #include "CExpanderText.h"
  17.  
  18. TCL_DEFINE_CLASS_D1( CExpanderText, CExpanderPane );
  19.  
  20.  
  21. /*
  22.  * CExpanderText constructor
  23.  *
  24.  * Default constructor - should only be called when created by a file read.
  25.  */
  26.  
  27. CExpanderText :: CExpanderText() : CExpanderPane()
  28. {
  29.     lineHeight = 0;
  30.     ascent = 0;
  31.  
  32.     TCL_END_CONSTRUCTOR
  33. }
  34.  
  35.  
  36. /*
  37.  * CExpanderText constructor
  38.  *
  39.  * Normal constructor - should always be called when created in code.
  40.  */
  41.  
  42. CExpanderText :: CExpanderText( CView *anEnclosure, CBureaucrat *aSupervisor, 
  43.                                 short aWidth, short aHeight, short aHLoc, short aVLoc, 
  44.                                 SizingOption aHSizing, SizingOption aVSizing )
  45.             : CExpanderPane( anEnclosure, aSupervisor, aWidth, aHeight, aHLoc, aVLoc,
  46.                      aHSizing, aVSizing )
  47. {
  48.     lineHeight = 0;
  49.     ascent = 0;
  50.  
  51.     TCL_END_CONSTRUCTOR
  52. }
  53.  
  54.  
  55. /*
  56.  * CExpanderText destructor
  57.  *
  58.  * Just a place-holder for Inspector
  59.  */
  60.  
  61. CExpanderText :: ~CExpanderText()
  62. {
  63.     TCL_START_DESTRUCTOR
  64. }
  65.  
  66.  
  67. /*
  68.  * TextSizeChanged method
  69.  *
  70.  * Updates expander when size of text has changed.
  71.  */
  72.  
  73. void CExpanderText :: TextSizeChanged( void )
  74. {
  75.     short    aWidth, aHeight;
  76.  
  77.     aHeight = CalcFrameHeight();
  78.     aWidth = CalcFrameWidth();
  79.     SetExpanderSize( aWidth, aHeight );
  80. }
  81.  
  82.  
  83. /*
  84.  * CalcLineHeight method
  85.  *
  86.  * Sets the lineHeight and ascent variables based on the current font settings
  87.  */
  88.  
  89. void CExpanderText :: CalcLineHeight( void )
  90. {
  91.     FontInfo    fontInfo;
  92.  
  93.     ForceNextPrepare();            // make sure we see any font change
  94.     Prepare();                    // setup drawing environment
  95.  
  96.     GetFontInfo( &fontInfo );    // get font info
  97.     lineHeight = fontInfo.ascent + fontInfo.descent + fontInfo.leading;
  98.     ascent = fontInfo.ascent;
  99. }
  100.  
  101.  
  102. /*
  103.  * CalcFrameHeight method
  104.  *
  105.  * Returns the height of the frame. This class just returns the size of one line of text.
  106.  */
  107.  
  108. short CExpanderText :: CalcFrameHeight( void )
  109. {
  110.     CalcLineHeight();
  111.     return lineHeight;
  112. }
  113.  
  114.  
  115. /*
  116.  * CalcFrameWidth method
  117.  *
  118.  * Returns the width of the frame. This class just returns the pane's width.
  119.  */
  120.  
  121. short CExpanderText :: CalcFrameWidth( void )
  122. {
  123.     return width;
  124. }
  125.  
  126.  
  127. /*
  128.  * ParentMessage method - OVERRIDE
  129.  *
  130.  * Handles kExpanderFontChanged messages. These indicate that the parent has changed
  131.  * the font characteristics of our drawing space. Must update our frame size.
  132.  */
  133.  
  134. void CExpanderText :: ParentMessage( long message, void *param )
  135. {
  136.     if ( message == kExpanderFontChanged ) {
  137.         TextSizeChanged();
  138.     }
  139.     else {
  140.         CExpanderPane::ParentMessage( message, param );
  141.     }
  142. }
  143.  
  144.  
  145. /*
  146.  * PutTo method - OVERRIDE
  147.  *
  148.  * Writes to the stream all the info we need to save.
  149.  */
  150.  
  151. void CExpanderText :: PutTo( CStream &stream )
  152. {
  153.     stream << lineHeight << ascent;
  154.  
  155.     CExpanderPane::PutTo( stream );
  156. }
  157.  
  158.  
  159. /*
  160.  * GetFrom method - OVERRIDE
  161.  *
  162.  * Reads from the stream all of the info that we saved.
  163.  */
  164.  
  165. void CExpanderText :: GetFrom( CStream &stream )
  166. {
  167.     stream >> lineHeight >> ascent;
  168.  
  169.     CExpanderPane::GetFrom( stream );
  170. }
  171.